package shopping.event;

import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import shopping.beans.CD;

public abstract class EventHandlerBase {
	private Vector<CD> cdList;

	public Vector<CD> getCDList() {
		if (cdList == null)
			cdList = new Vector<CD>();
		
		return cdList;
	}
	
	public abstract String getURL_To_Dispatch();
	
	public abstract void process(HttpServletRequest request, HttpServletResponse response); 
	
	public String execute(HttpServletRequest request, HttpServletResponse response) {
		
		HttpSession session = request.getSession();
		cdList = (Vector<CD>) session.getAttribute("shoppingcart");
		
		process(request, response); // ca^n` dinh. nghia~ lai o moi~ lop' event handler
		
		session.setAttribute("shoppingcart", cdList);
		
		return getURL_To_Dispatch(); // ca^n` dinh. nghia~ lai o moi~ lop' event handler
	}
}
